package com.phenix.apt;

import com.google.auto.service.AutoService;
import com.google.common.collect.Sets;
import com.phenix.annotation.apt.Instance;

import java.util.Set;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;

/**
 * @author  zhouphenix on 2017-2-21.
 */
@AutoService(Processor.class)//自动生成 javax.annotation.processing.IProcessor 文件
@SupportedSourceVersion(SourceVersion.RELEASE_8)//java版本支持
/*@SupportedAnnotationTypes({
       "com.phenix.annotation.apt.Instance"
})*/
public class AnnotationProcessor extends AbstractProcessor {
    /**文件相关的辅助类*/
    Filer mFiler;
    /**元素相关的辅助类*/
    private Elements mElements;
    /**日志相关的辅助类*/
    Messager mMessager;

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        mFiler = processingEnv.getFiler(); //文件相关辅助类
        mElements = processingEnv.getElementUtils();//元素相关辅助类
        mMessager = processingEnv.getMessager();//日志相关辅助类
        new InstanceProcessor().process(this, roundEnv);
        return true;
    }

    @Override
    public Set<String> getSupportedAnnotationTypes() {
        return Sets.newHashSet(Instance.class.getCanonicalName());
    }
}
